
<%@page import="java.util.List"%>
<script type='text/javascript'>
    $(document).ready(function() {
        $("button, input:submit, input:reset, input:button", "#pnl_reporte").button();
        $(".btn_detalle").button({
            icons: {primary: "ui-icon-arrow-4-diag"}
        });
        //$(".btn_descarga").button({
        //    icons: {primary: "ui-icon-arrow-4-diag"}
        //});
        $("#pnl_detalle").dialog({
            position: {my: "center", at: "top", of: window},
            closeText: "Cerrar",
            autoOpen: false,
            modal: true,
            width: 700,
            resizable: false,
            buttons: {
                "Imprimir": function() {
                    imprimir('#pnl_detalle');
                },
                "Cerrar": function() {
                    $(this).dialog("close");
                }
            }
        });
        $("#pnl_complementar").dialog({
            position: {my: "center", at: "top", of: window},
            closeText: "Cerrar",
            autoOpen: false,
            modal: true,
            width: 700,
            resizable: false,
            buttons: {
                "Guardar": function() {
                    $("#frm_complementar").submit();
                    $(this).dialog("close");
                    //$("#pnl_mensajes").dialog("option", "title", "Resultado de guardar").dialog("open");
                },
                "Cancelar": function() {
                    $(this).dialog("close");
                }
            }
        });
        $("#pnl_mensajes").dialog({
            position: {my: "center", at: "top", of: window},
            closeText: "Cerrar",
            autoOpen: false,
            modal: true,
            width: 700,
            resizable: false,
            buttons: {
                "Cerrar": function() {
                    $(this).dialog("close");
                }
            }
        });
    });
    function imprimir(id_div) {
        var printW = window.open(' ', 'popimpr');
        var title = $(id_div).dialog("option", "title");
        printW.document.write('<html><head><title>' + title + '</title>');
        printW.document.write('</head><body>');
        printW.document.write('<img src="http://www.cmoctezuma.com.mx/images/logo-moctezuma-cementos-concretos.png" width="250" height="50" alt="Logo">');
        printW.document.write('<br/><br/>');
        printW.document.write($(id_div).html());
        printW.document.write('</body></html>');
        printW.document.close();
        printW.print();
        printW.close();
        return true;
    }
    function dialogo(folio, accion) {
        if (accion === "de") {
            charge('#pnl_detalle', 'index?ac=' + accion + '&folio=' + folio);
            $("#pnl_detalle").dialog("option", "title", "Detalle del folio: " + folio);
            $("#pnl_detalle").dialog("open");
        } else {
            charge('#pnl_complementar', 'index?ac=' + accion + '&folio=' + folio);
            $("#pnl_complementar").dialog("option", "title", "Complementar el folio: " + folio);
            $("#pnl_complementar").dialog("open");
        }
    }
</script>
<a href="<%=request.getAttribute("url_repo").toString().equalsIgnoreCase("#ERROR_REPORTE") 
        ? "javascript:alert('Ocurrio un error al generar el reporte');window.close();" 
        : request.getAttribute("url_repo").toString()%>" target="_blank" class="button medium green"> Descargar Excel </a>
<br/><br/>
<div id="pnl_detalle" title="Detalle"></div>
<div id="pnl_complementar" title="Complementar"></div>
<div id="pnl_mensajes" title="Mensaje"></div>
<div id="pnl_reporte" class="wscroll">
    <table width='98%' cellpadding='0' cellspacing='0' id="tbl_reporte">
        <thead>
            <tr class="encabezado">
                <th>FOLIO</th>
                <th>CLIENTE</th>
                <th>ESTATUS</th>
                <th>FECHA INTERNET</th>
                <th>IMPORTE</th>
                <th>RECIBO DE COBRO SICE</th>
                <th>REFERENCIA BANCARIA</th>
                <th>Opc.</th>
            </tr>
        </thead>
        <% List<String[]> reportes = (List<String[]>) request.getAttribute("reporte");
            for (int i = 0; i < reportes.size(); i++) {
                String[] repo = reportes.get(i);%>
        <tbody>
            <tr class='<%=(i % 2 == 0 ? "fila_par" : "fila_non")%>'>
                <td>
                    <button name="save_customer" 
                            class="btn_detalle" 
                            title="Detalle de <%=repo[0]%>" 
                            onclick="dialogo('<%=repo[0]%>', 'de');" height="15"><%=repo[0]%></button>
                </td>
                <td><%
                    String cliente = repo[1];
                    if (cliente.length() > 40) {
                        out.println(cliente.substring(0, 40));
                    } else {
                        out.println(cliente);
                    }%>
                </td>
                <td align="center"><%=repo[2]%></td>
                <td align="center"><%=repo[4]%></td>
                <td align="right"><%=repo[6]%></td>
                <td align="center"><%=repo[3]%></td>
                <td align="center"><%=repo[5]%></td>
                <td align="right">
                    <% if (repo[5].compareToIgnoreCase("-") == 0) {%>
                    <input type="button" class="btn_complementar" value="+" title="Complementar <%=repo[0]%>" onclick="dialogo('<%=repo[0]%>', 'up');"/>
                    <%} else {
                        }%>
                </td>
            </tr> <% }%>
        </tbody>
    </table>
</div>
